package q189_rotate;

public class Solution_2{
    /*
    该方法超时
     */
    public void rotate(int[] nums, int k) {
        if (nums.length == 1 || k % nums.length == 0) {
            return;
        }
        // 用类似于冒泡排序的方式不停调换
        k = k % nums.length;
        int stopChangeIndex = 0;
        for (int i = nums.length - k; i < nums.length; i++) {
            int j = i;
            while (j > stopChangeIndex) {
                int temp = nums[j];
                nums[j] = nums[j - 1];
                nums[j - 1] = temp;
                j --;
            }
            stopChangeIndex ++;
        }
    }
}
